#include "file_dialog.h"
#include "window.h"
FileDialog::FileDialog(QWidget *parent)
	: QDialog(parent)
{
	this->setWindowTitle("选择文件类型");
	Allfiles =new QPushButton("选择所有文件");
	txtFiles =new QPushButton("选择txt文件");
	PicFiles =new QPushButton("选择图片");
	CppFiles =new QPushButton("选择C++源文件");
	FilePath =new QLineEdit();
	layout =new QGridLayout(this);
	layout->addWidget(Allfiles,0,0); // 对按钮进行布局管理
	layout->addWidget(txtFiles,0,1);
	layout->addWidget(PicFiles,1,0);
	layout->addWidget(CppFiles,1,1);
	layout->addWidget(FilePath,2,0,1,2);
	connect(Allfiles, SIGNAL(clicked()), this, SLOT(selectAllFiles())); //将对应的按钮与功能联系
	connect(txtFiles, SIGNAL(clicked()), this, SLOT(selectTxtFiles()));
	connect(PicFiles, SIGNAL(clicked()), this, SLOT(selectPicFiles()));
	connect(CppFiles, SIGNAL(clicked()), this, SLOT(selectCppFiles()));
}
FileDialog::~FileDialog()
{
}
void FileDialog::select(QString fileType){
	QString filePath=QFileDialog::getOpenFileName(this,"Select File","/home",fileType);
	FilePath->setText(filePath);
}
void FileDialog::selectAllFiles(){
	select("All (*)");
}
void FileDialog::selectTxtFiles(){
	select("TXT (*.txt)");
}
void FileDialog::selectPicFiles(){
	select("JPEG (*.jpeg);;JPG (*.jpg);;PNG (*.png)");
}
void FileDialog::selectCppFiles(){
	select("CPP (*.cpp)");
}
